package com.zttek.videoShareProject.modules.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zttek.videoShareProject.modules.model.Follow;
import com.zttek.videoShareProject.modules.mapper.FollowMapper;
import com.zttek.videoShareProject.modules.service.IFollowService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CBY
 * @since 2018-07-03
 */
@Service
public class FollowServiceImpl extends ServiceImpl<FollowMapper, Follow> implements IFollowService {
    @Autowired
    private FollowMapper followMapper;

    @Transactional
    public void insertFollow(Follow follow) throws Exception {
        followMapper.insert(follow);
    }

    @Transactional
    public void deleteFollw(Follow follow) throws Exception {
        EntityWrapper<Follow> ew = new EntityWrapper<Follow>();
        ew.where("follow_id={0}",follow.getFollowId())
                .andNew("follower_id={0}",follow.getFollowerId());
        followMapper.delete(ew);
    }

    @Transactional
    public Integer isFollow(Follow follow) throws Exception {
        Follow resultFollow = followMapper.selectOne(follow);
        if(resultFollow != null){
            return 1;
        }
        return 0;
    }
}
